<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Construct a RecursiveIteratorIterator</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="recursiveiteratoriterator.callhaschildren.html">RecursiveIteratorIterator::callHasChildren</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="recursiveiteratoriterator.current.html">RecursiveIteratorIterator::current</a></div>
 <div class="up"><a href="class.recursiveiteratoriterator.html">RecursiveIteratorIterator</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="recursiveiteratoriterator.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">RecursiveIteratorIterator::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.3)</p><p class="refpurpose"><span class="refname">RecursiveIteratorIterator::__construct</span> &mdash; <span class="dc-title">Construct a RecursiveIteratorIterator</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-recursiveiteratoriterator.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>RecursiveIteratorIterator::__construct</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.traversable.html" class="type Traversable">Traversable</a></span> <code class="parameter">$iterator</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = RecursiveIteratorIterator::LEAVES_ONLY</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Creates a <a href="class.recursiveiteratoriterator.html" class="classname">RecursiveIteratorIterator</a> from a <a href="class.recursiveiterator.html" class="classname">RecursiveIterator</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-recursiveiteratoriterator.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">iterator</code></em></dt>

     <dd>

      <p class="para">
       The iterator being constructed from. Either a
       <a href="class.recursiveiterator.html" class="classname">RecursiveIterator</a> or <strong class="classname">IteratorAggregate</strong>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">mode</code></em></dt>

     <dd>

      <p class="para">
       Optional mode. Possible values are
       <ul class="simplelist">
        <li class="member">
         <strong><code>RecursiveIteratorIterator::LEAVES_ONLY</code></strong>
         - The default. Lists only leaves in iteration.
        </li>
        <li class="member">
         <strong><code>RecursiveIteratorIterator::SELF_FIRST</code></strong>
         - Lists leaves and parents in iteration with parents coming first.
        </li>
        <li class="member">
         <strong><code>RecursiveIteratorIterator::CHILD_FIRST</code></strong>
         - Lists leaves and parents in iteration with leaves coming first.
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">flags</code></em></dt>

     <dd>

      <p class="para">
       Optional flag. Possible values are <strong><code>RecursiveIteratorIterator::CATCH_GET_CHILD</code></strong>
       which will then ignore exceptions thrown in calls to <span class="methodname"><strong>RecursiveIteratorIterator::getChildren()</strong></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-recursiveiteratoriterator.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-recursiveiteratoriterator.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="recursiveiteratoriterator.example.basic">
    <p><strong>Example #1 Iterating a RecursiveIteratorIterator</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-0-0-0'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-0-0-1'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-0-0'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-1-0-0'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-1-0-1'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-1-0'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'leaf-0-0'<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$iterator&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RecursiveIteratorIterator</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;</span><span style="color: #0000BB">RecursiveArrayIterator</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mode<br /></span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$iterator&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$leaf</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">&nbsp;=&gt;&nbsp;</span><span style="color: #0000BB">$leaf</span><span style="color: #DD0000">"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     Output with <em>$mode = RecursiveIteratorIterator::LEAVES_ONLY</em>
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
0 =&gt; leaf-0-0-0-0
1 =&gt; leaf-0-0-0-1
0 =&gt; leaf-0-0-0
0 =&gt; leaf-0-1-0-0
1 =&gt; leaf-0-1-0-1
0 =&gt; leaf-0-1-0
0 =&gt; leaf-0-0
</pre></div>
    </div>
    <div class="example-contents"><p>
     Output with <em>$mode = RecursiveIteratorIterator::SELF_FIRST</em>
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
0 =&gt; Array
0 =&gt; Array
0 =&gt; Array
0 =&gt; leaf-0-0-0-0
1 =&gt; leaf-0-0-0-1
1 =&gt; leaf-0-0-0
1 =&gt; Array
0 =&gt; Array
0 =&gt; leaf-0-1-0-0
1 =&gt; leaf-0-1-0-1
1 =&gt; leaf-0-1-0
2 =&gt; leaf-0-0
</pre></div>
    </div>
    <div class="example-contents"><p>
     Output with <em>$mode = RecursiveIteratorIterator::CHILD_FIRST</em>
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
0 =&gt; leaf-0-0-0-0
1 =&gt; leaf-0-0-0-1
0 =&gt; Array
1 =&gt; leaf-0-0-0
0 =&gt; Array
0 =&gt; leaf-0-1-0-0
1 =&gt; leaf-0-1-0-1
0 =&gt; Array
1 =&gt; leaf-0-1-0
1 =&gt; Array
2 =&gt; leaf-0-0
0 =&gt; Array
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="recursiveiteratoriterator.callhaschildren.html">RecursiveIteratorIterator::callHasChildren</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="recursiveiteratoriterator.current.html">RecursiveIteratorIterator::current</a></div>
 <div class="up"><a href="class.recursiveiteratoriterator.html">RecursiveIteratorIterator</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
